home *** CD-ROM | disk | FTP | other *** search
/ Network Support Library / RoseWare - Network Support Library.iso / pressgen / an312x.exe / INSTALL.C < prev    next >
C/C++ Source or Header  |  1994-01-28  |  6KB  |  182 lines

  1. /*
  2.  ████████████████████████████████████████████████████████████████████████████
  3.  █                                                                          █
  4.  █ install.c                                                                █
  5.  █                                                                          █
  6.  █ Creates a job server and job queue to process DOS commands submitted by  █
  7.  █ submit.exe                                                               █
  8.  ████████████████████████████████████████████████████████████████████████████
  9. */
  10.  
  11. #include <stdio.h>
  12. #include <conio.h>
  13. #include <stdlib.h>
  14. #include <ctype.h>
  15. #include <dos.h>
  16. #include <dir.h>
  17. #include <nwcalls.h>
  18. #include "..\doit.h"
  19.  
  20. #define NWDOS
  21.  
  22. NWCCODE            cCode;
  23. struct ffblk    ffblk;
  24. int                found;
  25. DWORD            queueID,
  26.                 serverID;
  27. NWFILE_HANDLE    fileHandle;
  28. NWCONN_HANDLE    connID;
  29. NWCONN_NUM        connNumber;
  30. char NWFAR        userName[48];
  31. char NWFAR        serverName[48];
  32. char            response;
  33. NWFLAGS NWFAR    installed;
  34. NWSEGMENT_DATA    segment;
  35.  
  36. void main()
  37. {
  38.     found = findfirst(JOBSERV_PATH, &ffblk, FA_DIREC);
  39.     if (found != 0) {
  40.         printf("You must create the queue directory\n");
  41.         printf("%s before installing the job server.\n", JOBSERV_PATH);
  42.         exit(-1);
  43.     }
  44.  
  45.     cCode = NWCallsInit(NULL, NULL);
  46.     if (cCode != 0) {
  47.         printf("Unable to initialize NetWare interface\n");
  48.         exit(-1);
  49.     }
  50.  
  51.     /* get the connection ID of the server you're installing on */
  52.     cCode = NWGetDefaultConnectionID(&connID);
  53.     if (cCode != 0) {
  54.         printf("Unable to get connection ID of default server\n");
  55.         exit(-1);
  56.     }
  57.  
  58.     /* create job server object */
  59.     cCode = NWCreateObject(connID, JOBSERV_NAME, OT_DOIT, BF_STATIC, BS_LOGGED_READ | BS_OBJECT_WRITE);
  60.     if (cCode == 0)
  61.         printf("Created job server bindery object\n");
  62.     else {
  63.         switch (cCode) {
  64.             case 0x89EE :    printf("Job server bindery object already created on default server\n");
  65.                     response = ' ';
  66.                     do {
  67.                         printf("Continue anyway?  (y/n)");
  68.                         response = toupper(getche());
  69.                         printf("\n");
  70.                     } while ((response !=  'Y') && (response  !=  'N'));
  71.                     if (response == 'N')
  72.                         exit(-1);
  73.                     break;
  74.             case 0x89F5 :    printf("You must be supervisor or supervisor-equivalent to install job server\n");
  75.                     exit(-1);
  76.                     break;
  77.             default :    printf("Call to NWCreateObject failed\n");
  78.                     exit(-1);
  79.                     break;
  80.         }
  81.     }
  82.  
  83.     /* create a password for the job server */
  84.     cCode = NWChangeObjectPassword(connID, JOBSERV_NAME, OT_DOIT, "", JOBSERV_PWORD);
  85.     if (cCode == 0)
  86.         printf("Set job server password\n");
  87.     else {
  88.         printf("Call to NWChangeObjectPassword failed, cCode = %X\n", cCode);
  89.         exit(-1);
  90.     }
  91.  
  92.     /* see if accounting is installed; if so, create account balance property */
  93.     cCode = NWQueryAccountingInstalled(connID, &installed);
  94.     if (installed == 1) {
  95.         cCode = NWCreateProperty(connID, JOBSERV_NAME, OT_DOIT, "ACCOUNT_BALANCE", BF_ITEM | BF_STATIC, BS_OBJECT_READ | BS_SUPER_WRITE);
  96.         if (cCode != SUCCESSFUL) {
  97.             printf("Unable to create Account Balance property for job server object\n");
  98.             exit(-1);
  99.         }
  100.  
  101.         /* set account balance to allow unlimited credit */
  102.         segment = (NWSEGMENT_DATA)calloc(128, sizeof(BYTE));
  103.         segment[4] = 0x80;
  104.         cCode = NWWritePropertyValue(connID, JOBSERV_NAME, OT_DOIT, "ACCOUNT_BALANCE", 1, segment, 0);
  105.         if (cCode != SUCCESSFUL) {
  106.             printf("Unable to set account balance for job server object\n");
  107.             exit(-1);
  108.         }
  109.  
  110.         /* add job server's bindery ID to the servers' ACCOUNT_SERVERS property */
  111.         /* first get file server name */
  112.         cCode = NWGetFileServerName(connID, serverName);
  113.         if (cCode != SUCCESSFUL) {
  114.             printf("Unable to get name of default file server\n");
  115.             exit(-1);
  116.         }
  117.  
  118.         /* now add object to property */
  119.         cCode = NWAddObjectToSet(connID, serverName, OT_FILE_SERVER, "ACCOUNT_SERVERS", JOBSERV_NAME, OT_DOIT);
  120.         if (cCode == SUCCESSFUL)
  121.             printf("Added job server to ACCOUNT_SERVERS set\n");
  122.         else {
  123.             printf("Unable to add job server to server's ACCOUNT_SERVERS property\n");
  124.             exit(-1);
  125.         }
  126.     }
  127.  
  128.     /* create a job queue */
  129.     cCode = NWCreateQueue(connID, JOBSERV_NAME, OT_DOIT_Q, 0, JOBSERV_PATH, &queueID);
  130.     if (cCode == 0)
  131.         printf("Created job queue\n");
  132.     else {
  133.         printf("Call to NWCreateQueue failed, cCode = %X\n", cCode);
  134.         if ((cCode == 0x8998) || (cCode == 0x899C))
  135.             printf("Invalid queue directory path\n");
  136.             exit(-1);
  137.     }
  138.  
  139.     /* get your connection number */
  140.     cCode = NWGetConnectionNumber(connID, &connNumber);
  141.     if (cCode != 0) {
  142.         printf("Unable to get your connection number to default server\n");
  143.         exit(-1);
  144.     }
  145.  
  146.     /* get your user name */
  147.     cCode = NWGetConnectionInformation(connID, connNumber, userName, NULL, NULL, NULL);
  148.     if (cCode != 0) {
  149.         printf("Unable to get your user name\n");
  150.         exit(-1);
  151.     }
  152.  
  153.     /* add your user to the set of queue users */
  154.     cCode = NWAddObjectToSet(connID, JOBSERV_NAME, OT_DOIT_Q, "Q_USERS", userName, OT_USER);
  155.     if (cCode == 0)
  156.         printf("Added your object to queue users set\n");
  157.     else {
  158.         printf("Call to NWAddObjectToSet failed, cCode = %X\n", cCode);
  159.         exit(-1);
  160.     }
  161.  
  162.     /* add your user to the set of queue operators */
  163.     cCode = NWAddObjectToSet(connID, JOBSERV_NAME, OT_DOIT_Q, "Q_OPERATORS", userName, OT_USER);
  164.     if (cCode == 0)
  165.         printf("Added your object to queue operators set\n");
  166.     else {
  167.         printf("Call to NWAddObjectToSet failed, cCode = %X\n", cCode);
  168.         exit(-1);
  169.     }
  170.  
  171.     /* add your new server to the set of queue servers */
  172.     cCode = NWAddObjectToSet(connID, JOBSERV_NAME, OT_DOIT_Q, "Q_SERVERS", JOBSERV_NAME, OT_DOIT);
  173.     if (cCode == 0)
  174.         printf("Added job server to queue servers set\n");
  175.     else {
  176.         printf("Call to NWAddObjectToSet failed, cCode = %X\n", cCode);
  177.         exit(-1);
  178.     }
  179.  
  180.     printf("Job server installed\n");
  181. }
  182.